package com.zzyl.controller;

import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:NursingPlanController
 * package:com.zzyl.controller.customer
 * description:
 *
 * @author 刘
 * @version 1.0
 * @Create 2024/5/31 14:39
 */
@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     * @return
     */
    @ApiOperation("查询所有护理计划")
    @GetMapping
    public ResponseResult<List<NursingPlanVo>> getAllNursingPlan(){
        List<NursingPlanVo> nursingPlanVo = nursingPlanService.getAllNursingPlan();
        return ResponseResult.success(nursingPlanVo);
    }


    @ApiOperation("新增护理计划")
    @PostMapping
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 条件分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @ApiOperation("条件分页查询")
    @GetMapping("/search")
    public ResponseResult getByLimit(@RequestParam(value = "name", required = false) String name,
                                     @RequestParam Integer pageNum,
                                     @RequestParam Integer pageSize,
                                     @RequestParam(value = "status", required = false) Integer status){
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.getByLimit(name,pageNum,pageSize,status);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Integer id){

        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    @ApiOperation("修改")
    @PutMapping("/{id}")
    public ResponseResult updateById(@PathVariable Integer id,@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.updateById(id,nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 根据计划id删除计划表数据
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        nursingPlanService.deleteById(id);
        return ResponseResult.success();
    }

    /**
     * 启用禁用
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult putStatusById(@PathVariable Integer id,@PathVariable Integer status){
        nursingPlanService.updateStatusById(id,status);
        return ResponseResult.success();
    }

}
